#ifndef _UTILS_MEMORY_H_
#define _UTILS_MEMORY_H_

#include <utils/type_traits.h>


inline void* operator new (size_t size, void* ptr) { return ptr; }

namespace utils
{

namespace detail
{

template <typename _Type, typename _OK = void>
struct copy_helper
{
  void operator ()(_Type const& from, _Type& to)
  {
    Serial.println("toto");
    Serial.flush();
    to.~_Type();
    new(&to) _Type(from);
  }
};

template <typename _Basic>
struct copy_helper<_Basic, typename utils::enable_if<utils::is_basic_type<_Basic>::value>::type>
{
  void operator ()(_Basic const& from, _Basic& to)
  { to = from; }
};

} // detail

template <typename _Type>
void copy(_Type const& from, _Type& to)
{ reinterpret_cast<detail::copy_helper<_Type>*>(0x0)->operator ()(from, to); }

} // utils

#endif // _UTILS_MEMORY_H_
